import { HttpException, HttpStatus } from '@nestjs/common';

export default class ErrorExcption extends HttpException {
  code: number;
  constructor(error: string | Error, code: number) {
    let msg: string;
    if (typeof error === 'string') {
      msg = error;
    } else {
      msg = (error as Error).message ?? '未知错误';
    }
    super({ message: msg, code: code }, HttpStatus.OK);
    this.code = code;
    this.message = msg;
  }

  getCode(): number {
    return this.code;
  }
}
